import logging
from redis import StrictRedis


class Config(object):
    """项目的配置"""
    # 默认开启调试
    DEBUG = True
    # 默认日志等级
    LOG_LEVEL = logging.DEBUG

    # base64.b64encode(os.urandom(48))
    SECRET_KEY = "gCKNf3MptMGSvY+U0nD7F+g37Nf4kfLzAqIXlB9TwAA7U9BUSDu08blFRzWtbXhN"

    # 数据库配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:jinxin1108@127.0.0.1:3306/info190528"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 在请求结束时，SQLAlchemy会自动执行一次db.session.commit
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # Redis的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # Session保存位置
    SESSION_TYPE = "redis"
    # 开启Session签名
    SESSION_USE_SIGNER = True
    # 指定session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # 设置session为过期模式
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2


class DevelopmentConfig(Config):
    """开发环境"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境"""
    DEBUG = False
    LOG_LEVEL = logging.ERROR


class UnitTestConfig(Config):
    """单元测试环境"""
    DEBUG = True
    TESTING = True


config = {
    "dev": DevelopmentConfig,
    "pro": ProductionConfig,
    "test": UnitTestConfig
}